﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading.Tasks;

namespace FMS.Formulation.Licensing.Engine
{

    internal class WMILogicalDiskInfo
    {
        private const string WIN32_LOGICALDISK = "Win32_LogicalDisk";

        private const string DEVICEID = "DeviceID";

        private const string DESCRIPTION = "Description";

        private int _id = 0;

        private string deviceID = string.Empty;

        private string deviceDescription = string.Empty;

        public int ID => _id;

        public string DeviceID => deviceID;

        public string Description => deviceDescription;

        public void Read()
        {
            WqlObjectQuery query = new WqlObjectQuery("SELECT DeviceID, Description FROM Win32_LogicalDisk WHERE DeviceID='C:'");
            ManagementScope scope = new ManagementScope("\\root\\cimv2");
            ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(scope, query);
            try
            {
                ManagementObjectCollection managementObjectCollection = managementObjectSearcher.Get();
                foreach (ManagementObject item in managementObjectCollection)
                {
                    if (item.Properties["DeviceID"].Value != null)
                    {
                        deviceID = item.Properties["DeviceID"].Value.ToString();
                    }
                    if (item.Properties["Description"].Value != null)
                    {
                        deviceDescription = item.Properties["Description"].Value.ToString();
                    }
                }
            }
            catch
            {
            }
        }
    }

}
